<template>
  <div class="boxContent">
    <div class="appBox">
      <div class="searchList">
        <el-form :model="state.params"
                 ref="FormInstance "
                 class="boxFrom">
          <div class="searchBox">
            <template v-for="(item, index) in state.totalInputColumns"
                      :key="index">
              <el-form-item v-if="item.type == 'input'">
                <el-input v-model="state.params[item.key]"
                          :placeholder="item.label"></el-input>
              </el-form-item>
              <el-form-item v-if="item.type == 'select'">

                <el-cascader v-model="state.params[item.key]"
                             :options="state.propsCity"
                             :props="state.props"
                             :placeholder="item.label"
                             clearable
                             v-if="item.key == 'city'" />
              </el-form-item>
              <el-form-item v-if="item.type == 'time'">
                <el-date-picker v-model="state.params[item.key]"
                                type="daterange"
                                value-format="YYYY-MM-DD"
                                start-placeholder="开始日期"
                                range-separator="至"
                                end-placeholder="结束日期"
                                :placeholder="item.label" />
              </el-form-item>
            </template>
          </div>

          <el-form-item class="btns">
            <el-button v-preventReClick
                       type="primary"
                       plain
                       @click="methods.handleAction('query')">搜索</el-button>
            <el-button v-preventReClick
                       @click="methods.handleAction('reset')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="tabaleBox">
        <el-table border
                  :data="state.tableData"
                  style="width: 100%"
                  :header-cell-style="{ color: '#000' }">

          <el-table-column prop="time"
                           label="反馈时间"
                           show-overflow-tooltip
                           align="center"
                           width="180">
          </el-table-column>
          <el-table-column prop="name"
                           label="反馈用户"
                           width="120"
                           show-overflow-tooltip
                           align="left">
          </el-table-column>
          <el-table-column prop="phone"
                           label="手机号"
                           width="120"
                           show-overflow-tooltip
                           align="center">
          </el-table-column>
          <el-table-column prop="accept"
                           label="是否采纳"
                           width="120"
                           show-overflow-tooltip
                           align="center">
            <template #default="scope">
              <span class="primary"
                    v-if="scope.row.accept == '2'">已采纳</span>
              <span class="success"
                    v-else>待采纳</span>

            </template>
          </el-table-column>
          <el-table-column prop="content"
                           label="反馈内容"
                           show-overflow-tooltip
                           align="left">
          </el-table-column>
          <el-table-column prop="pictures"
                           label="预览图片"
                           align="center"
                           width="240">
            <template #default="scope">
              <el-carousel :interval="2000"
                           indicator-position="outside"
                           v-if="scope.row?.pictures"
                           height="50px">
                <el-carousel-item v-for="(i,k) in JSON.parse(scope.row?.pictures)"
                                  :key="k">
                  <el-image style="width: 90px; height: 30px;margin-top: 10px;"
                            :key="i"
                            :src="i"
                            :zoom-rate="1.2"
                            :max-scale="7"
                            :preview-teleported="true"
                            :min-scale="0.2"
                            :preview-src-list="JSON.parse(scope.row?.pictures)"
                            :initial-index="k"
                            fit="cover" />
                </el-carousel-item>
              </el-carousel>

            </template>
          </el-table-column>
          <el-table-column prop=""
                           label="操作"
                           align="center"
                           width="120">
            <template #default="scope">
              <div class="btnsDatil flex_c">
                <!-- 其它操作 -->
                <div @click="methods.handleAction('adopt', scope.row)"
                     v-permission="1121"
                     v-if="scope.row.accept != '2'">采纳意见</div>

              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="
                     pagination">
        <el-pagination background
                       v-model:current-page="state.params.pageNum"
                       v-model:page-size="state.params.pageSize"
                       :page-sizes="[10, 20, 30, 50]"
                       layout="total, sizes, prev, pager, next, jumper"
                       :total="state.totalSize"
                       @size-change="methods.handleSizeChange"
                       @current-change="methods.handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import {
  ref,
  onMounted,
  reactive,
  toRefs,
  defineComponent,
  getCurrentInstance,
} from "vue";
import Editor from '@/components/Editor.vue'
import { useRouter } from "vue-router";
import { ElMessage, ElMessageBox } from "element-plus";
const router = useRouter();
const app = getCurrentInstance()?.proxy;
const initState = () => {
  return {
    dialogVisible: false,
    totalSize: 0,
    tableData: [],
    params: {
      pageNum: 1,
      pageSize: 10,

    },
    totalInputColumns: [
      { key: "name", label: "反馈人姓名", type: "input" },
      { key: "phone", label: "手机号", type: "input" },
      { key: "time", label: "选择时间", type: "time" },
    ],
  };
};
const state = reactive(initState());
onMounted(() => {
  methods.getDataList();
});
const methods = {

  handleAction (type, data) {
    switch (type) {
      case "reset": // 重置
        state.params = initState().params;
        break;
      case "query":
        methods.getDataList();
        break;
      case "adopt": // 
        ElMessageBox.confirm("请确认是否采纳该意见", "采纳意见", {
          confirmButtonText: "同意",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            app.$post("/feedback/update", {
              accept: 2,
              id: data.id
            }).then((res) => {
              if (res.code == 200) {
                ElMessage({
                  type: "success",
                  message: "已采纳",
                });
                methods.getDataList();

              }
            });
          })
        break;


    }
  },

  getDataList () {
    let data = JSON.parse(JSON.stringify(state.params))
    data.time = data.time ? data.time.join() : ""
    app.$get("/feedback/query", data)
      .then((res) => {
        if (res.code == 200) {
          state.tableData = res.data.list;
          state.totalSize = res.data.total;
        }
      });
  },
  //分页变化
  handleSizeChange () {
    state.params.pageNum = 1;
    methods.getDataList();
  },
  //表格翻页
  handleCurrentChange () {
    methods.getDataList();
  },
};
</script>

<style lang="scss" scoped>
.appBox {
  background: #fff;
  border-radius: 5px;
  padding: 20px;
  height: calc(100% - 20px);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;

  .tabaleBox {
    overflow: hidden;
    flex: 1;
  }
  .btnsDatil {
    color: #0079fe;
    cursor: pointer;
  }
  .pagination {
    margin-top: 20px;
    height: 50px;
    display: flex;
    justify-content: flex-end;
  }
  ::v-deep(.el-dialog__body) {
    padding: 20px 30px !important;
  }
  .imgs {
    flex-wrap: wrap;
    .forbox {
      height: 150px;
      margin: 10px 0 0 10px;
    }
    .imgBox {
      height: 100%;
      width: auto;
    }
    .videoBox {
      width: auto;
      height: 100%;
    }
  }
}
</style>
